package jcrosswords.domain;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;

@Entity
public class ClueResponse implements Serializable {
	
	private static final long serialVersionUID = 1L;
	
	private Integer id;
	private String clue;
	private String response;
	private Database database;
	private Collection<ClueResponseTag> clueResponseTags;
	
	public ClueResponse() {
	}
	
	public ClueResponse(String clue, String response, Database database, Collection<ClueResponseTag> clueResponseTags) {
		setClue(clue);
		setResponse(response);
		setDatabase(database);
		setClueResponseTags(clueResponseTags);
	}
	
	@Id
	@GeneratedValue(strategy=GenerationType.AUTO)
	public Integer getId() {
		return id;
	}
	
	private void setId(Integer id) {
		this.id = id;
	}

	public String getClue() {
		return clue;
	}
	
	public void setClue(String clue) {
		this.clue = clue;
	}

	public String getResponse() {
		return response;
	}

	public void setResponse(String response) {
		this.response = response;
	}
	
	@ManyToOne
	public Database getDatabase() {
		return database;
	}

	public void setDatabase(Database database) {
		this.database = database;
	}
	
	@ManyToMany
	public Collection<ClueResponseTag> getClueResponseTags() {
		if(clueResponseTags == null)
			clueResponseTags = new ArrayList<ClueResponseTag>();
		return clueResponseTags;
	}

	public void setClueResponseTags(
			Collection<ClueResponseTag> clueResponseTags) {
		this.clueResponseTags = clueResponseTags;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((id == null) ? 0 : id.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		final ClueResponse other = (ClueResponse) obj;
		if (id == null) {
			if (other.id != null)
				return false;
		} else if (!id.equals(other.id))
			return false;
		return true;
	}
	
	@Override
	public String toString() {
		return getClue() + ": " + getResponse();
	}

}